import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import prismjs from 'vite-plugin-prismjs'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    prismjs({
      languages: ['json', 'js', 'css', 'html'],
      //  languages: 'all',
      plugins: ['line-numbers'], //配置显示行号插件
      theme: 'solarizedlight', //主题名称
      css: true
    })
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src') // 设置 `@` 指向 `src` 目录
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        charset: false,
        additionalData: '@import "@/assets/scss/var.scss";'
      }
    }
  },
  base: './', // 设置打包路径
  server: {
    host: '0.0.0.0', // ip
    port: 3000, // 设置服务启动端口号
    open: true, // 设置服务启动时是否自动打开浏览器
    cors: true, // 允许跨域
    strictPort: true,
    // 设置代理，根据我们项目实际情况配置
    proxy: {
      '/api': {
        target: 'https://api.bilibili.com/',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/api/, ''),
        headers: {
          referer: 'https://www.bilibili.com',
          origin: 'https://www.bilibili.com'
        }
      },
      '/zhihu': {
        target: 'https://www.zhihu.com/',
        rewrite: (path) => path.replace(/^\/zhihu/, '')
      }
    }
  }
})
